// ==UserScript==
// @name           Travian: Static Village Names
// @Author         vimperator
// @version        1.0
// @namespace      vimperator
// @description    Static Village Names
// @include        http://*.travian.*/*
// @exclude        http://forum.travian.*/*
// ==/UserScript==

var Names = new Array();
Names[0] = new Array("-148", "-70", "[Jumping Jack]..15c");
Names[1] = new Array("-150", "-67", "[Digger]...........1st (defense)");
Names[2] = new Array("-151", "-68", "[Pacman]..........6444 (near 1st)");
Names[3] = new Array("-157", "-78", "[Frogger]..........9c (defense)");
Names[4] = new Array("-155", "-79", "[Archon]...........lumber (near 9c)");
Names[5] = new Array("-146", "-72", "[Xonix].............6444 (near 15c)");
Names[6] = new Array("-142", "-82", "[HERMANNSTADT].....9c");

var XPFirst = XPathResult.FIRST_ORDERED_NODE_TYPE;
var XPList  = XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE;

function main(){
	if (!init())return;
};

function find(xpath,xpres){
  var ret = document.evaluate(xpath,document,null,xpres,null);
  return  xpres == XPFirst ? ret.singleNodeValue : ret;
};

function elem(tag,idt,idv,class,content){
	var ret=document.createElement(tag);
	if(content)ret.innerHTML=content;
	if(idt)ret.setAttribute(idt,idv);
	if(class)ret.className=class;
	return ret;
};

function init(){
	var z=find('//a[@class="active_vl"]',XPList);
	if(z.snapshotLength==0)return false;
	activetown=z.snapshotItem(0).textContent;
	var tl=document.getElementById('lright1');
	var tdtown=tl.getElementsByTagName('td');
	for(var i=0;i<tdtown.length;i++){
		if(tdtown[i].className=='right'){
			var tdcoord=tdtown[i].getElementsByTagName('td');
			for(var j=0; j<Names.length; j++) {
				if(tdcoord[0].textContent == "("+Names[j][0] && tdcoord[2].textContent == Names[j][1]+")") {
					town_td = elem('td');
					town_td.setAttribute('nowrap', '1');
					town_name = elem('span','id','','c0',Names[j][2]);
					town_td.appendChild(town_name);
					tdtown[i].parentNode.appendChild(town_td);

				};
			};
		};
	};
    
	return true;
};

main();